using Uantek.Device.Communication.Models;

namespace Uantek.Device.Communication.Protocols.Interfaces
{
    /// <summary>
    /// 设备协议接口
    /// </summary>
    public interface IDeviceProtocol : IDisposable
    {
        /// <summary>
        /// 协议名称
        /// </summary>
        string ProtocolName { get; }

        /// <summary>
        /// 协议版本
        /// </summary>
        string Version { get; }

        /// <summary>
        /// 数据接收事件
        /// </summary>
        event EventHandler<DeviceDataModel>? DataReceived;

        /// <summary>
        /// 状态变化事件
        /// </summary>
        event EventHandler<DeviceStatus>? StatusChanged;

        /// <summary>
        /// 连接设备
        /// </summary>
        /// <returns>连接结果</returns>
        Task<CommunicationResult> ConnectAsync();

        /// <summary>
        /// 断开设备连接
        /// </summary>
        /// <returns>断开结果</returns>
        Task<CommunicationResult> DisconnectAsync();

        /// <summary>
        /// 发送命令
        /// </summary>
        /// <param name="command">命令</param>
        /// <param name="parameters">参数</param>
        /// <returns>命令执行结果</returns>
        Task<CommunicationResult<string>> SendCommandAsync(string command, Dictionary<string, object>? parameters = null);

        /// <summary>
        /// 解析设备数据
        /// </summary>
        /// <param name="rawData">原始数据</param>
        /// <returns>解析后的设备数据</returns>
        Task<DeviceDataModel?> ParseDeviceDataAsync(byte[] rawData);

        /// <summary>
        /// 构建命令数据
        /// </summary>
        /// <param name="command">命令</param>
        /// <param name="parameters">参数</param>
        /// <returns>命令数据</returns>
        Task<byte[]> BuildCommandAsync(string command, Dictionary<string, object>? parameters = null);

        /// <summary>
        /// 验证数据完整性
        /// </summary>
        /// <param name="data">数据</param>
        /// <returns>是否有效</returns>
        bool ValidateData(byte[] data);

        /// <summary>
        /// 获取支持的通信类型
        /// </summary>
        /// <returns>支持的通信类型列表</returns>
        IEnumerable<string> GetSupportedTransportTypes();
    }
}